const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sortList:[
      {name:'按演练均分倒序',sortField:'rehearsal',sortType:'desc'},
      {name:'按演练均分正序',sortField:'rehearsal',sortType:'asc'},
      {name:'按通关均分倒序',sortField:'pass',sortType:'desc'},
      {name:'按通关均分正序',sortField:'pass',sortType:'asc'},
    ],
    sortShow:false,
    params: {
      currentPage: 1,
      id: '',
      pageSize: 20,
      sortField: "",
      sortType: "",
    },
    examInfo:{},
    list: [],
    orgId: app.globalData.userInfo.orgId,
    fields:[
      {
        prop: 'name',
        label: '姓名',
        width: '200'
      },
      {
        prop: 'orgName',
        label: '所属组织',
        width: '200'
      },
      {
        prop: 'avgRehearsalScore',
        label: '演练均分',
        width: '150'
      },
      {
        prop: 'avgPassScore',
        label: '通关均分',
        width: '150'
      }
    ],
    total: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '考试统计详情',
    })
    const {id,name,time} = options
    this.setData({
      examInfo:{
        name,
        time
      },
      'params.id': id
    })
    this.getRank()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  sortHandle () {
    this.setData({
      sortShow:true
    })
  },
  loadMore () {
    const { total, list, params } = this.data
    const { currentPage } = params
    if (total > list.length) {
      this.setData({
        'params.currentPage': currentPage + 1
      })
      this.getRank()
    }
  },
  getRank () {
    const { currentPage } = this.data.params 
    app.api.post({
      url: 'report_activity_activityCoachingRank',
      data: this.data.params
    }).then(res => {
      let { list } = this.data
      currentPage === 1 ? (list = res.list) : list.push(...res.list)
      this.setData({ list, total: res.total })
    })
  },
  getTrainDetail () {
    const params = this.data.queryForm
    app.api.post({
      url: 'qryStudyDetail',
      data: params
    }).then(res=>{
      this.setData({
        list:res.list || [],
        hasFixed:false
      })
      console.log(res,'=====');
    })
  },
  sortSelect(e) {
    const index = e.detail
    const item = this.data.sortList[index]
    console.log(item,'item========');
    this.setData({
      'params.currentPage': 1,
      'params.sortField': item.sortField,
      'params.sortType': item.sortType
    })
    this.getRank()
  },
})